import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Utils {
  Utils._();

  static Utils? _instance;

  static Utils get instance => _instance ??= Utils._();

  //获取图片路径
  String getImagePathPNG(imageName) {
    return "assets/images/${imageName}.png";
  }

  //获取图片路径
  String getImagePathGIF(imageName) {
    return "assets/images/${imageName}.gif";
  }

  //设置背景图片
  BoxDecoration decorationImage(imageName, radius) {
    return BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(radius)),
        image: DecorationImage(
            image: AssetImage(Utils.instance.getImagePathPNG(imageName)),
            fit: BoxFit.cover));
  }

  //设置背景图片
  BoxDecoration decorationColor(color, radius) {
    return BoxDecoration(
      color: color,
      borderRadius: BorderRadius.all(Radius.circular(radius)),
    );
  }

  AppBar appBarLeft(BuildContext context, titleContent) {
    return AppBar(
      scrolledUnderElevation: 0.0,
      backgroundColor: Colors.transparent,
      leading: IconButton(
          icon: Image.asset(Utils.instance.getImagePathPNG("icon_left_arrow"),
              width: 24.w, height: 24.h),
          onPressed: () {
            Navigator.of(context).pop();
          }),
      title: Center(
          child: Text(
        titleContent,
        style: TextStyle(fontSize: 16.sp, color: Colors.black),
      )),
    );
  }
}
